﻿
@{
    ViewBag.Title = "编辑专题";
    Layout = "~/Views/Shared/_Member.cshtml";
}

<div class="row p10 bcolor" style="overflow:auto;">
    <div class="layui-col-md11 pt30">
        <form class="layui-form" id="dataForm">
            <div class="layui-form-item layui-hide">
                <label class="layui-form-label">专题ID</label>
                <div class="layui-input-block">
                    <input type="text" name="ID" id="ID" class="layui-input" value="@ViewBag.SpecialID">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">专题封面</label>
                <div class="layui-input-inline">
                    <input type="text" name="Img" id="Img" class="layui-input layui-hide" value="">
                    <img src="" id="imgDisplay" alt="图片" style="width:190px;height:120px" onerror="imageError(event)" />
                </div>
                <div class="layui-form-mid layui-word-aux"><a href="javascript:void(0)" class="href" onclick="javascript: { open_cover(); }">编辑封面</a></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">专题名称</label>
                <div class="layui-input-block">
                    <input type="text" name="Name" placeholder="请输入专题名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">专题内容</label>
                <div class="layui-input-block">
                    <div id="editor"></div>
                </div>
            </div>
            <div class="layui-form-item pt30">
                <div class="layui-input-block">
                    <a href="javascript:void(0)" class="layui-btn layui-btn-normal" onclick="javascript: { special.submit(); }">保存</a>
                    <a href="/Member/Special@(ViewBag.Suffix)" class="layui-btn layui-btn-primary">取消</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    var editor = new window.wangEditor('#editor'); editor.customConfig.uploadImgServer = '/Base/WangEditorUpload';
    editor.customConfig.uploadImgMaxSize = 1024 * 1024;
    editor.customConfig.uploadImgMaxLength = 2;
    editor.customConfig.customAlert = function (info) {
        layer.msg(info);
    }
    editor.create();
    var special = new Special();
    $(function () {
        special.paras.specialId = $('#ID').val();
        if (special.paras.specialId) {
            special.initSpecial();
        }
    });

    function Special() {
        this.paras = {
            specialId: null
        };
        this.initSpecial = function () {
            $.post('/member/GetMemberSpecialResult', this.paras, function (result) {
                $('#dataForm').setForm(result.data);
                $('#imgDisplay').attr('src', fileurl + result.data.Img);
                editor.txt.html(result.data.Content);
            });
        };
        this.submit = function () {
            var paras = $('#dataForm').getForm();
            paras.Content = editor.txt.html();
            console.log(paras);
            $.post('/member/UserEditSpecialResult', paras, function (result) {
                layer.confirm('保存成功', {
                    closeBtn: 0,
                    btn: ['确定']
                }, function () {
                    window.parent.parent.location = '/member/special';
                });
            });
        };
    };

    var cover_win = null, cover_data = null;
    function open_cover() {
        cover_data = null;
        cover_win = layer.open({
            type: 2,
            title: '编辑封面',
            shadeClose: true,
            shade: 0.8,
            area: ['462px', '750px'],
            content: '/Home/Cover'
        });
    };

    function save_cover() {
        var paras = { base64: cover_data };
        $('#imgDisplay').attr('src', cover_data);
        $.post('/base/FileUpload', paras, function (result) {
            $('#Img').val(result.data);
        });
        layer.close(cover_win);
    };

    function close_cover() {
        layer.close(cover_win);
    };
</script>